import Redis from 'ioredis';
import { Controller, Get, Req, Version } from '@nestjs/common';
import { AppService } from './app.service';
import { InjectRedis } from '@nestjs-modules/ioredis';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';

@Controller()
export class AppController {
  constructor(
    @InjectRedis() private readonly redis: Redis,
    private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }
  @Get('account')
  @ApiOperation({ summary: '获取用户账号信息' })
  @ApiResponse({ status: 200, description: '返回用户账号信息', type: String })
  @Version('1')
  async account(@Req() request: Request): Promise<string> {
    await this.redis.set('key', 'Redis data!');
    console.log("request.headers Version 1.0");
    return `Version 1.0;`;
  }
  @Get('account')
  @ApiOperation({ summary: '获取用户账号信息' })
  @ApiResponse({ status: 200, description: '返回用户账号信息', type: String })
  @Version('2')
  async account2(@Req() request: Request): Promise<string> {
    console.log("request.headers Version 2.0");
    return `Version 2.0`;
  }
  @Get('available')
  @ApiOperation({ summary: '检查Redis连接是否可用' })
  @ApiResponse({ status: 200, description: '返回Redis连接状态', type: String })
  async set(@Req() request: Request): Promise<string> {
    await this.redis.set('key', 'Redis data!');
    console.log("request.headers Version 1.0");
    return `Version 1.0;`;
  }
}
